//
//  ByUIShopCarVC.m
//  oc_knowledge
//
//  Created by pro on 17/1/13.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByUIShopCarVC.h"

// vc
#import "ByUIProductDetailVC.h"         // 详情页
#import "ByUIOrderCommitVC.h"           // 订单确认

// cell
#import "ByCellShopCarListItem.h"

// api
#import "ByApiShopCar.h"

// model
#import "ByModelShopCar.h"

// view
#import "ByViewShopCarToolBar.h"        // 工具栏
#import "ByViewStoreSectionHeader.h"    // 组头视图（显示店铺信息）

@interface ByUIShopCarVC () <UITableViewDelegate, UITableViewDataSource>
// view
@property (nonatomic, strong) UITableView *table;
@property (nonatomic, strong) ByViewShopCarToolBar *toolBar;    // 工具栏


// data

@property (nonatomic, strong) NSMutableArray *items;            // 有效商品数组（店铺model）
@property (nonatomic, strong) NSMutableArray *selectItems;      // 选中商品数组（店铺model）

@property (nonatomic, strong) NSMutableArray *invalidItems;     // 失效商品数组（商品model）
@end

@implementation ByUIShopCarVC
#pragma mark - 懒加载
// 工具栏
- (ByViewShopCarToolBar *)toolBar {
    
    if (!_toolBar) {
        _toolBar = [[ByViewShopCarToolBar alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 40)];
        _toolBar.bottom = SCREEN_HEIGHT - 64;
        [self.view addSubview:_toolBar];
    }
    return _toolBar;
}
// 选中的购物车商品数组
- (NSMutableArray *)selectItems {
    
    if (!_selectItems) {
        _selectItems = [[NSMutableArray alloc] init];
    }
    return _selectItems;
}
// 购物车中的总商品数组
- (NSMutableArray *)items {
    
    if (!_items) {
        _items = [[NSMutableArray alloc] init];
    }
    return _items;
}
// 购物车中的总商品数组
- (NSMutableArray *)invalidItems {
    
    if (!_invalidItems) {
        _invalidItems = [[NSMutableArray alloc] init];
    }
    return _invalidItems;
}

#pragma mark - view method
- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.title = @"购物车";
    
    [self addCustomItemviews:@[[self editButton]] position:ByNavigationItemPositionModeRight];
    
    // 创建table
    [self createTableView];
    // 设置回调
    [self setupToolBarBlock];
    
    // 设置table和toolbar的位置尺寸信息
    // 购物车控制器的父控制器是导航控制器，其再上一层若是空，则说明是push过来的（没有标签栏），否则有标签栏
    // 有标签栏则不用返回键，反之需要返回键
    if (self.parentViewController.parentViewController) {
        self.toolBar.bottom = SCREEN_HEIGHT - 64 - 49;
        self.table.height = self.toolBar.top;
    } else {
        [self addLeftBackBarButtonItem];
    }
}
- (void)viewWillAppear:(BOOL)animated {
    
    [super viewWillAppear:animated];
    
    [self.table.mj_header beginRefreshing];
}
- (void)viewWillDisappear:(BOOL)animated {
    
    [super viewWillDisappear:animated];
    
    [ByCoreToolAlert hideHud];
}
#pragma mark - 回调配置
- (void)setupToolBarBlock {
    
    __weak typeof(self) weakself = self;
    
    self.toolBar.selectAllBlock = ^(BOOL selected){
        
        [weakself.items enumerateObjectsUsingBlock:^(ByModelShopCar *storeModel, NSUInteger index, BOOL * _Nonnull stop) {
            
            storeModel.selected = selected;
            
            [storeModel.item_list enumerateObjectsUsingBlock:^(ByModelShopCarListItem *model, NSUInteger itemIndex, BOOL * _Nonnull stop) {
                
                model.selected = selected;
            }];
        }];
        [weakself.table reloadData];
        // 计算总价
        [weakself calculatedTotalPrice];
    };
    
    self.toolBar.deleteAllBlock = ^{
        
        // 多选删除
        [weakself multipleDeletes];

    };
    self.toolBar.settleBlock = ^{
        
        // 去结算
        [weakself gotoPay];
    };
}
- (void)setupHeaderBlock:(ByViewStoreSectionHeader *)header section:(NSInteger)section {
    
    header.selectBlock = ^ (BOOL selected) {
        
        ByModelShopCar *storeModel = self.items[section];
        storeModel.selected = selected;
        [storeModel.item_list enumerateObjectsUsingBlock:^(ByModelShopCarListItem *model, NSUInteger itemIndex, BOOL * _Nonnull stop) {
            
            model.selected = selected;
        }];
        
        [self.table reloadData];
        
        // 每次选中一个商品后都要判断是否全选了
        [self checkIsSelectAll];
        
        // 计算总价
        [self calculatedTotalPrice];
    };
}
- (void)setupCellBlock:(ByCellShopCarListItem *)cell indexPath:(NSIndexPath *)indexPath {
    
    cell.modifyBlock = ^ (int count) {
        
        ByModelShopCar *storeModel = self.items[indexPath.section];
        ByModelShopCarListItem *itemModel = storeModel.item_list[indexPath.row];
        itemModel.count = @(count);
        
        // 更新购物车（修改数量）
        [self updateShopCarProduct:itemModel count:count indexPath:indexPath];
        
    };
    cell.selectBlock = ^ (BOOL selected) {
        
        ByModelShopCar *storeModel = self.items[indexPath.section];
        ByModelShopCarListItem *model = storeModel.item_list[indexPath.row];
        model.selected = selected;
        
        // 每次对店铺model操作，都需要判断店铺是否全选了
        [self checkStoreIsSelectAll:storeModel];
        
        [self.table reloadData];
        
        // 每次选中一个商品后都要判断是否全选了
        [self checkIsSelectAll];
        
        // 计算总价
        [self calculatedTotalPrice];
    };
    cell.deleteBlock = ^ {
        
        ByModelShopCar *storeModel = self.items[indexPath.section];
        ByModelShopCarListItem *itemModel = storeModel.item_list[indexPath.row];
        
        // 更新购物车（删除商品）
        [self deleteShopCarProduct:itemModel storeModle:storeModel];
    };
}

#pragma mark - 创建视图
- (UIButton *)editButton {
    
    UIButton *editBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    editBtn.frame = CGRectMake(0, 0, 40, 40);
    [editBtn setTitle:@"编辑" forState:UIControlStateNormal];
    [editBtn setTitle:@"完成" forState:UIControlStateSelected];
    [editBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [editBtn addTarget:self action:@selector(editAction:) forControlEvents:UIControlEventTouchUpInside];
    return editBtn;
}
// 创建表视图
- (void)createTableView {
    
    self.table = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT - 64 - self.toolBar.height) style:UITableViewStyleGrouped];
    self.table.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.table.delegate = self;
    self.table.dataSource = self;
    [self.view addSubview:self.table];
    
    self.table.tableFooterView = [UIView new];
    self.table.separatorStyle = UITableViewCellSeparatorStyleNone;
    
    ByCoreRefreshGifHeader *t_header = [ByCoreRefreshGifHeader headerWithRefreshingBlock:^{
        
        [self getShopCarList];
    }];
    self.table.mj_header = t_header;
}



#pragma mark - 点击事件
- (void)editAction:(UIButton *)sender {
    
    sender.selected = !sender.selected;
    
    // 改变工具栏的编辑状态
    self.toolBar.editing = sender.selected;
    
    // 重新加载table，来改变cell的编辑状态
    [self.table reloadData];
}
// 清空失效商品
- (void)emptyInvalids {
    
    [self.invalidItems removeAllObjects];
    [self.table reloadData];

}


#pragma mark - 网络请求
- (void)getShopCarList {
    
    if (![self loginIfNoUserId]) {
        return;
    }
    
    self.toolBar.userInteractionEnabled = NO;
    
    ByNetParamsModel *params = [[ByNetParamsModel alloc] init];
    params.uid = BY_USER.uid;
    params.s_id = BY_USER.s_id;
    [ByApiShopCar getShopCarList:params success:^(ByNetBaseResult *result) {
        
        self.toolBar.userInteractionEnabled = YES;

        [self.table.mj_header endRefreshing];
        
        [self.items removeAllObjects];
        [self.items addObjectsFromArray:result.data];
       
        [self.table reloadData];
        
        // 重新加载后要检查是否全选（实际上一定是未全选的）
        [self checkIsSelectAll];
        // 重新加载后要重新计算价格（实际上一定是0元）
        [self calculatedTotalPrice];
        
    } failure:^(ByNetBaseResult *result) {
        [self.table.mj_header endRefreshing];
        [ByCoreToolAlert showFailureWithText:result.msg];
    }];
}

// 删除购物车商品
- (void)deleteShopCarProduct:(ByModelShopCarListItem *)model storeModle:(ByModelShopCar *)storeModel {
    
    if (![self loginIfNoUserId]) {
        return;
    }
    
    ByNetParamsModel *params = [[ByNetParamsModel alloc] init];
    params.uid = BY_USER.uid;
    params.id = model.id;
    params.s_id = BY_USER.s_id;

    [ByCoreToolAlert showLoadind:@"正在删除..."];
    [ByApiShopCar deleteProductAtShapcar:params success:^(ByNetBaseResult *result) {
        
        [ByCoreToolAlert showSuccessWithText:result.msg];
        
        NSMutableArray *itemListTmp = [NSMutableArray arrayWithArray:storeModel.item_list];
        [itemListTmp removeObject:model];
        if (itemListTmp.count == 0) {
            [self.items removeObject:storeModel];
        } else {
            storeModel.item_list = itemListTmp.copy;
            // 每次对店铺model操作，都需要判断店铺是否全选了
            [self checkStoreIsSelectAll:storeModel];
        }
        
        [self.table reloadData];
        
        // 每次删除一个商品后都要判断是否全选了
        [self checkIsSelectAll];
        
        // 计算总价
        [self calculatedTotalPrice];
        
    } failure:^(ByNetBaseResult *result) {
        [ByCoreToolAlert showFailureWithText:result.msg];
    }];
}
- (void)multipleDeletes {
    
    if (![self loginIfNoUserId]) {
        return;
    }
    
    NSMutableArray *idArray = [[NSMutableArray alloc] init];
    // 遍历所有店铺，找到需要多个删除的商品
    [self.items enumerateObjectsUsingBlock:^(ByModelShopCar *storeModel, NSUInteger index, BOOL * _Nonnull stop) {
        
        NSMutableArray *itemListTemp = [NSMutableArray arrayWithArray:storeModel.item_list];
        // 遍历一个店铺下的所有商品
        [itemListTemp enumerateObjectsUsingBlock:^(ByModelShopCarListItem *model, NSUInteger itemIndex, BOOL * _Nonnull stop) {
            // 判断该商品是否被选中，用以删除
            if (model.selected) {
                [idArray addObject:model.id];
            }
        }];
    }];
    
    ByNetParamsModel *params = [[ByNetParamsModel alloc] init];
    params.uid = BY_USER.uid;
    params.id = [idArray componentsJoinedByString:@","];
    params.s_id = BY_USER.s_id;

    [ByCoreToolAlert showLoadind:@"正在删除..."];
    [ByApiShopCar deleteProductAtShapcar:params success:^(ByNetBaseResult *result) {
        
        [ByCoreToolAlert showSuccessWithText:result.msg];
        
        NSMutableIndexSet *set = [[NSMutableIndexSet alloc] init];  // 记录哪一个店铺被删完了

        // 遍历所有店铺
        [self.items enumerateObjectsUsingBlock:^(ByModelShopCar *storeModel, NSUInteger index, BOOL * _Nonnull stop) {
            
            NSMutableArray *itemListTemp = [NSMutableArray arrayWithArray:storeModel.item_list];
            NSMutableIndexSet *itemListSet = [[NSMutableIndexSet alloc] init];
            // 遍历一个店铺下的所有商品
            [itemListTemp enumerateObjectsUsingBlock:^(ByModelShopCarListItem *model, NSUInteger itemIndex, BOOL * _Nonnull stop) {
                // 判断该商品是否被选中，用以删除
                if (model.selected) {
                    [itemListSet addIndex:itemIndex];
                }
            }];
            // 商品数组删除需要删除的商品
            [itemListTemp removeObjectsAtIndexes:itemListSet.copy];
            // 如果商品删完了，则店铺也应该从items中删除，否则店铺保留，仅修改店铺中的商品数组
            if (itemListTemp.count == 0) {
                [set addIndex:index];
            } else {
                storeModel.item_list = itemListTemp.copy;
            }
        }];
        [self.items removeObjectsAtIndexes:set.copy];
        
        [self.table reloadData];
        
        // 每次删除一个商品后都要判断是否全选了
        [self checkIsSelectAll];
        
        // 计算总价
        [self calculatedTotalPrice];
        
    } failure:^(ByNetBaseResult *result) {
        [ByCoreToolAlert showFailureWithText:result.msg];
    }];
}

// 更新购物车
- (void)updateShopCarProduct:(ByModelShopCarListItem *)model count:(NSInteger)count indexPath:(NSIndexPath *)indexPath {
    
    if (![self loginIfNoUserId]) {
        return;
    }
    
    ByNetParamsModel *params = [[ByNetParamsModel alloc] init];
    params.uid = BY_USER.uid;
    params.s_id = BY_USER.s_id;
    params.id = model.id;
    params.count = [NSString stringWithFormat:@"%li", count];
    
    [ByCoreToolAlert showLoadind:@"正在修改数量..."];
    [ByApiShopCar updateProductForShapcar:params success:^(ByNetBaseResult *result) {
        
        [ByCoreToolAlert hideHud];
        
        [self.table reloadData];
        
        // 计算总价
        [self calculatedTotalPrice];
        
    } failure:^(ByNetBaseResult *result) {
        [ByCoreToolAlert showFailureWithText:result.msg];
        
        [self.table reloadData];
        
        // 计算总价
        [self calculatedTotalPrice];
    }];
    
}


#pragma mark - UITableViewDataSource UITableViewDelegate
// 设置组数
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
    // 单独一组为已失效的商品
    return self.items.count + (self.invalidItems.count > 0 ? 1 : 0);
}
// 设置行数
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    if (section < self.items.count) {
        ByModelShopCar *storeModel = self.items[section];
        return storeModel.item_list.count;
    } else {
        return self.invalidItems.count;
    }
}
// 设置单元格属性
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (indexPath.section < self.items.count) {
        
        ByCellShopCarListItem *cell = [tableView dequeueReusableCellWithIdentifier:@"normalCell"];
        if (cell == nil) {
            cell = [[ByCellShopCarListItem alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"normalCell"];
        }
        
        // 设置属性和编辑模式
        ByModelShopCar *storeModel = self.items[indexPath.section];
        cell.model = storeModel.item_list[indexPath.row];
        cell.isEditing = self.toolBar.editing;
        
        // 设置回调处理
        [self setupCellBlock:cell indexPath:indexPath];
        
        return cell;
    }
    else {
        ByCellShopCarListItem *cell = [tableView dequeueReusableCellWithIdentifier:@"invalidCell"];
        if (cell == nil) {
            cell = [[ByCellShopCarListItem alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"invalidCell"];
        }
        
        cell.model = self.invalidItems[indexPath.row];
        
        return cell;
    }
    

}
// 设置单元格行高
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 100;
}
// 设置组头高
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    if (section < self.items.count) {
        return 44;
    } else {
        return 44;
    }
}
- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    if (section < self.items.count) {
        ByViewStoreSectionHeader *header = [[ByViewStoreSectionHeader alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, [self tableView:tableView heightForHeaderInSection:section])];
        // 设置数据
        header.storeModel = self.items[section];
        // 设置回调
        [self setupHeaderBlock:header section:section];
        
        return header;
    } else {
        UIView *invalidView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, [self tableView:tableView heightForHeaderInSection:section])];
        UIImageView *tagView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, invalidView.height * 0.8 * 77 / 48, invalidView.height * 0.8)];
        tagView.image = [UIImage imageNamed:@"ShopCar_invalid"];
        tagView.x = invalidView.width / 2;
        tagView.y = invalidView.height / 2;
        [invalidView addSubview:tagView];
        return invalidView;
    }
    
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    if (section < self.items.count) {
        return 10;
    } else {
        return 50;
    }
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    if (section < self.items.count) {
        UIView *normalFooter = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, [self tableView:tableView heightForFooterInSection:section])];
        UIView *line = [[UIView alloc] initWithFrame:CGRectMake(0, 0, normalFooter.width, 0.5)];
        line.backgroundColor = [UIColor colorWithWhite:0.8 alpha:1];
        [normalFooter addSubview:line];
        return normalFooter;
    } else {
        UIView *emptyView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, [self tableView:tableView heightForFooterInSection:section])];
        emptyView.backgroundColor = [UIColor whiteColor];
        UIButton *emptyBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        NSString *str = @"清空失效商品";
        emptyBtn.titleLabel.font = FONT(15);
        [emptyBtn setTitle:str forState:UIControlStateNormal];
        [emptyBtn setTitleColor:KShopCarThemeColor forState:UIControlStateNormal];
        [emptyBtn addTarget:self action:@selector(emptyInvalids) forControlEvents:UIControlEventTouchUpInside];
        emptyBtn.frame = CGRectMake(0, 0, [str getSizeOfString:15].width + 30, 35);
        emptyBtn.x = emptyView.width / 2;
        emptyBtn.y = emptyView.height / 2;
        [emptyView addSubview:emptyBtn];
        emptyBtn.layer.cornerRadius = 8;
        emptyBtn.layer.borderColor = KShopCarThemeColor.CGColor;
        emptyBtn.layer.borderWidth = 1;
        return emptyView;
    }
}
// 单元格点击事件
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
    
    // TODO: 正式的时候需要用商品id进行跳转
    ByUIProductDetailVC *vc = [[ByUIProductDetailVC alloc] init];
    ByModelShopCar *storeModel = self.items[indexPath.section];
    ByModelShopCarListItem *itemModel = storeModel.item_list[indexPath.row];
    vc.pid = itemModel.p_id;
    [self by_normalPush:vc hasNavi:YES];
}
// 右滑删除
- (UITableViewCellEditingStyle)tableView:(UITableView *)tableView editingStyleForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return self.toolBar.editing ? UITableViewCellEditingStyleNone : UITableViewCellEditingStyleDelete;
}
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return @"删除";
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
    
    if (editingStyle == UITableViewCellEditingStyleDelete) {
        
        if (indexPath.section < self.items.count) {
            
            ByModelShopCar *storeModel = self.items[indexPath.section];
            ByModelShopCarListItem *itemModel = storeModel.item_list[indexPath.row];
            
            // 更新购物车（删除商品）
            [self deleteShopCarProduct:itemModel storeModle:storeModel];

        } else {

            [self.invalidItems removeObjectAtIndex:indexPath.row];
            [self.table reloadData];
        }
        
    }
}


#pragma mark - 其他辅助
// 计算总价
- (CGFloat)calculatedTotalPrice {
    
    __block CGFloat total = 0.0;
    __block int selectCount = 0;
    // 遍历店铺model，取出每个店铺的下的商品数组再次遍历，计算总价
    [self.items enumerateObjectsUsingBlock:^(ByModelShopCar *storeModel, NSUInteger idx, BOOL * _Nonnull stop) {
        
        [storeModel.item_list enumerateObjectsUsingBlock:^(ByModelShopCarListItem *model, NSUInteger idx, BOOL * _Nonnull stop) {
            
            CGFloat price = model.price.floatValue;     // 单价
            int count = model.count.intValue;           // 数量
            
            if (model.selected) {
                selectCount ++;
                total += (price * count);
            }
        }];
    }];
    
    self.toolBar.totalPrice = total;
    self.toolBar.selectCount = selectCount;

    
    return total;
}

// 判断是否全选了
- (void)checkIsSelectAll {
    
    __block BOOL isSelectAll = YES;

    if (self.items.count == 0) {
        isSelectAll = NO;
    }

    // 遍历店铺model
    [self.items enumerateObjectsUsingBlock:^(ByModelShopCar *stroeModel, NSUInteger idx, BOOL * _Nonnull stop) {
        
        if (stroeModel.selected == NO) {
            isSelectAll = NO;
            *stop = YES;
        }
    }];
    
    self.toolBar.selectAll = isSelectAll;
}
// 判断某店铺下是否已经全选
- (void)checkStoreIsSelectAll:(ByModelShopCar *)storeModel {
    
    __block BOOL isSelectAll = YES;
    
    // 遍历店铺model
    [storeModel.item_list enumerateObjectsUsingBlock:^(ByModelShopCarListItem *model, NSUInteger idx, BOOL * _Nonnull stop) {
        
        if (model.selected == NO) {
            isSelectAll = NO;
            *stop = YES;
        }
    }];
    
    storeModel.selected = isSelectAll;
}

// 如果用户没登录就去登录
- (BOOL)loginIfNoUserId {
    
    if (!BY_USER) {
        ByUINLoginVC *vc = [[ByUINLoginVC alloc] init];
        ByBaseNaviController *navi = [[ByBaseNaviController alloc] initWithRootViewController:vc];
        [self presentViewController:navi animated:YES completion:nil];
        return NO;
    }
    return YES;
}

// 寻找选中的商品，并跳转到结算界面
- (void)gotoPay {

    NSMutableArray *selectedProducts = [[NSMutableArray alloc] init];
    [self.items enumerateObjectsUsingBlock:^(ByModelShopCar *storeModel, NSUInteger idx, BOOL * _Nonnull stop) {
        
        // 店铺model的selected属性选中，说明该店铺下商品已全部选中
        if (storeModel.selected) {
            
            [selectedProducts addObject:storeModel];
        }
        // 在店铺model的selected属性为未选中的情况下，其下也可能有选中商品
        else {
            NSMutableArray *temp = [[NSMutableArray alloc] init];
            [storeModel.item_list enumerateObjectsUsingBlock:^(ByModelShopCarListItem *itemModel, NSUInteger index, BOOL * _Nonnull stop) {
                
                if (itemModel.selected) {
                    [temp addObject:itemModel];
                }
            }];
            // 有选中的商品
            if (temp.count != 0) {
                [selectedProducts addObject:storeModel];
                storeModel.item_list = temp.copy;
                
            }
        }
        
    }];
    
    if (selectedProducts.count == 0) {
        [ByCoreToolAlert showOnlyText:@"请至少选择一件商品^o^"];
        return;
    }
    
    ByUIOrderCommitVC *vc = [[ByUIOrderCommitVC alloc] init];
    vc.selectedPorducts = selectedProducts;
    vc.totalPrice = [self calculatedTotalPrice];
    [self by_normalPush:vc hasNavi:YES];
}


@end
